home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Tele / R / RRHost2.0Graphics < prev    next >
Encoding:
Text File  |  1987-05-25  |  10.9 KB  |  238 lines  |  [TEXT/MSWD]

  1.  
  2. MSGP
  3. ----
  4. The Macintosh Standard Graphics Protocol by Scott Watson
  5. The Macintosh Standard Graphics Protocol is an attempt to standardize (or
  6. at least provide a common subset of functions) the rapidly growing desire
  7. to send QuickDraw graphics over a modem.  This protocol has been constructed 
  8. with several essential properties in mind:
  9. 1) It must give access to the most frequently used QuickDraw routines.
  10. 2) It must have the least amount of overhead necessary to reduce the lag
  11.    between transmission and actual display on the user's terminal.
  12. 3) It must be error checked and acknowledged by the recipient to prevent
  13.    a line spike from causing a system crash due to execution of QuickDraw
  14.    routines with erroneously received parameters.
  15. 4) It must be easily imp,edented in any communications program, must not
  16.    be language specific (as long as the QuickDraw routines used are
  17.    accessable through a given language), and it must be small enough to
  18.    be constructed as an unloadable segment for when it's not in use.
  19. 5) It must be completely transparent to the user (no confusing "options"
  20.    or necessary commands for the user to become entangled with), and must
  21.    be completely controllable by the host.
  22. 6) It must allow transmission of the user's mouse cursor when the mouse
  23.    button is pressed to allow 2-way real time graphics functions.
  24. 7) There must be no need to document the protocol in your users' manual.
  25. Acceptance of this standard will ensure that your program will be compatible 
  26. with the other programs that have adopted this standard, and will work with 
  27. the Lazarus BBS program soon to be released from The FreeSoft Company. This 
  28. program will appear as a local Macintosh application (mouse buttons, graphics, 
  29. animation, dialog boxes, etc.) to the user of your program once connected. 
  30. To foster the acceptance of this graphics standard, we will distribute the
  31. BBS program at low or no cost, provide a debugging host to those trying to 
  32. implement this protocol, and make this standard public domain.
  33. Although it is a public domain protocol, I would feel grateful if you
  34. would make mention of me as the creator of the protocol in your users'
  35. manual should you make mention of it.
  36. Overview
  37. --------
  38. Throughout these specs, we will refer to two different machines, the host
  39. is the computer running a BBS or similar program.  The remote is the 
  40. computer running your communications program.  All numbers are given
  41. in decimal.
  42. In a TTY or other textual information mode, the remote should constantly
  43. trap the receipt of an ASCII code 26.  Once this occurs, you need to trap
  44. for the following characters in order: 16,04, and 12.  These are called
  45. the signiture bytes.  When you receive these bytes in that order, you are
  46. to immediately enter the graphics mode and send out a Type 45 packet
  47. (Acknowledge Graphics On).  If you don't receive the above sequence within
  48. three seconds of receiving the ASCII code 26, consider the 26 to be a
  49. fluke and return to your textual processing.
  50. The host should ensure that there has been at least 1 second of silence
  51. on the line before sending the signiture bytes.
  52. What Happens When You Enter The Graphics Mode
  53. ---------------------------------------------
  54. There is only one flag you need to keep track of while in the graphics
  55. mode - whether or not the host wants to allow the remote to send Type
  56. 49 packets (MouseDown Report).  When you initially enter the graphics
  57. mode, this flag is reset so that MouseDown events are not reported over
  58. the modem.
  59. Updates are not allowed either, so it is imperative that you disable any
  60. menu choices or other actions that would botch the display while in the
  61. graphics mode.  Actually, you are given a great deal of freedom of what
  62. you can do while in the graphics mode, as long as you are capable of
  63. restoring the screen yourself after it's been botched by a Desk Accessory
  64. or other function.
  65. There is a failsafe in case the remote should lose carrier while in the
  66. graphics mode.  Your program should look for the user to type COMMAND-X,
  67. and exit the graphics mode if it is in operation.  It's recommended that
  68. you don't document this, rather, let the host do it immediately upon
  69. receiving the Type 45 packet from the remote.  Since the host can cause
  70. your program to jump back and forth between the graphics and textual
  71. modes, you don't lose any of the capabilities of your software, such as
  72. file transfers, desk accessories, etc. that would otherwise botch the
  73. screen.
  74. Upon entering the graphics mode, you should display a type 1 (modal
  75. dialog or alert appearance) style window using the rectangle:
  76. 30,10,330,503.  This window takes up nearly all of the screen below the
  77. menu bar, cannot be moved, removed, or sized through user mouse control.
  78. In other words, it's awfully hard to screw up as long as you pay attention
  79. to the above requirements.  The above rectangle is important as M.S.G.P.
  80. commands are assumed to operate in that area only.
  81. There is an exception to the above.  The command types between 100
  82. and 255 are reserved for your use.  If you have special needs for the
  83. graphics mode, such as setting up a MacPaint-type drawing interface, you
  84. could use one of the special commands to set up the window using different
  85. coordinates, leaving room for tools and other information.  However, when
  86. your program is a remote, it has to have the ability to use the above
  87. coordinates as a default.
  88. Now we've entered the graphics mode, drawn our window, and sent back the
  89. Type 45 packet.  What's next?
  90. Data Flow
  91. ---------
  92. Data flow is nothing more than an exchange of packets and acknowledgements,
  93. much like the XMoDpSPprotocol.  However, since this is an interactive
  94. mode, there is no timeouts waiting for the next packet, and packet exchange
  95. is actually in two directions.
  96. A packet is variable length, and is in the following general format:
  97. SOP/LEN/COM/DAT/DAT/DAT/DAT.../CHK
  98. SOP - Start of packet byte (arbitrarily set as ASCII code 3)  The remote
  99. continually looks for an ASCII 3, and can assume any other characters are
  100. line spikes.
  101. LEN - The number of bytes following, not including the checksum.
  102. COM - The packet command type (these are numbered from 1 to 50 and are
  103. explained below.
  104. DAT - The data, which will be used as the parameters for the command.
  105. CHK - The checksum, which is the sum of the LEN, COM and DAT bytes,
  106. logically ANDed with 127.
  107. After receiving a complete packet, the remote should send either an
  108. ACK (ASCII code 6) if the checksum matches, or a NAK (ASCII code 21) if
  109. it doesn't.  You should set a timeout of 3 seconds to receive the full
  110. packet once the SOP has been received, and then automatically NAK the
  111. packet if it never comes through.  You send the ACK after the command is
  112. actually executed, to allow further parameter error checking if desired.
  113. The host will continue to re-send NAKed packets until an ACK is received.
  114. All DAT bytes are assumed to be unsigned (0 - 255).  Integers are sent
  115. with the most significant byte first.  All parameters are sent in the
  116. same order as is documented in the QuickDraw section of Inside Macintosh.
  117. The only exception is the Scroll command, which differs slightly from
  118. the QuickDraw ScrollRect function as documented below.
  119. The Command Types and Their QuickDraw Functions
  120. -----------------------------------------------
  121. 1) SetCursor
  122. 2) HideCursor
  123. 3) ShowCursor
  124. 4) ObscureCursor
  125. 5) LineTo
  126. 6) Line
  127. 7) BackPat
  128. 8) PenSize
  129. 9) PenMode
  130. 10) Move
  131. 11) PenNormal
  132. 12) MoveTo
  133. 13) PenPat
  134. 14) HidePen
  135. 15) ShowPen
  136. 16) TextFont
  137. 17) TextFace
  138. 18) TextMode
  139. 19) TextSize
  140. 20) DrawChar
  141. 21) DrawString
  142. 22) FrameRect
  143. 23) PaintRect
  144. 24) EraseRect
  145. 25) InvertRect
  146. 26) FillRect
  147. 27) FrameOval
  148. 28) PaintOval
  149. 29) EraseOval
  150. 30) InvertOval
  151. 31) FillOval
  152. 32) FrameRoundRect
  153. 33) PaintRoundRect
  154. 34) EraseRoundRect
  155. 35) InvertRoundRect
  156. 36) FillRoundRect
  157. 37) FrameArc
  158. 38) PaintArc
  159. 39) EraseArc
  160. 40) InvertArc
  161. 41) FillArc
  162. 50) InitCursor
  163. Non-QuickDraw Packets
  164. ---------------------
  165. 42) reserved for future use.
  166. 43) MouseEnable (no parameters) - When you receive this packet set the
  167. mouse flag so that any MouseDown event in the graphics window will send
  168. a Type 49 packet.
  169. 44) MouseDisable (no parameters) - Reset your mouse flag so that no
  170. MouseDown events are reported to the host.
  171. 45) AcknowledgeGraphicsOn (no parameters) - send this as soon as you enter
  172. the graphics mode to let the host know you have responded to the
  173. signiture bytes and are ready for M.S.G.P. commands.
  174. 46) reserved for future use.
  175. 47) Scroll(therect: Rect; X,Y:INTEGERS) - This is just like the ScrollRect
  176. function in QuickDraw, except that the region handle is not sent.  If the
  177. most significant bytes of X or Y is non-zero, the least significant bytes
  178. are deemed to be negative.
  179. 48) Exit Graphics Mode (no parameters) - This is your signal from the host
  180. to return to your TTY or textual mode.
  181. 49) MouseReport(X,Y:INTEGERS) - convert the global coordinates of the
  182. MouseDown event in the graphics window to local coordinates.  Remember,
  183. your mouse flag must have been set through a Type 43 command before you
  184. would send this packet type.
  185. Types 100-255: Not currently part of this protocol and reserved for use
  186. with your program communicating with like programs.
  187. A Typical Session
  188. -----------------
  189. The following are the actual bytes SENT by the host and remote.  My
  190. comments are in parentheses.  The numbers are in decimal.
  191. Host: 26,16,4,12
  192. (The host sends the signiture bytes)
  193. Remote: 3,1,45,46
  194. (The remote acknowledges with a Type 45 packet)
  195. Host: 3,5,12,0,25,0,25,67
  196. (The Host sends a MoveTo(25,25) packet (Type 12))
  197. Remote: 6
  198. (The Remote ACKS the packet)
  199. Host 3,3,16,0,0,19
  200. (The Host sends a TextFont(0) packet (Type 16))
  201. Remote: 6
  202. Host: 3,3,19,0,12,34
  203. (The Host sends a TextSize(12) packet)
  204. Remote: 6
  205. Host: 3,7,21,5,72,69,76,76,79,21
  206. (The Host sends a DrawString("\005HELLO") packet. Notice that whenever
  207. parameters would be a pointer for an actual QuickDraw call, the actual
  208. bytes pointed to would be sent in an M.S.G.P. packet.  Remember that a 
  209. Pascal string starts out with a byte indicating it's length).
  210. Remote: 6
  211. Host: 3,5,22,0,200,0,200,1,34,1,34,113
  212. (This is a FrameRect(200,200,290,290) packet)
  213. Remote: 21
  214. (Remote's didn't get the right checksum and NAKs it!)
  215. Host: 3,5,22,0,200,0,200,1,34,1,34,113
  216. Remote: 6
  217. (OK, noe the remote got it right)
  218. Host: 3,9,13,119,137,143,143,119,152,248,248,51
  219. (This is a PenPat packet with one of the patterns in the Control Panel
  220. Desk Accessory)
  221. Remote: 6
  222. Host: 3,1,43,44
  223. (The host enables the remote's mouse)
  224. Remote: 6
  225. (the remote now presses his mouse button with the cursor pointing at
  226. local coordinates X=24, Y=100)
  227. Remote: 3,5,49,0,24,0,100,50
  228. Host: 6
  229. (The host should always ACK a Type 49 packet as long as the checksum is
  230. correct, even if the mousepress was not in a valid area - just ignore it)
  231. Keyboard
  232. --------
  233. The keyboard is supported at all times for the remote.  The host can
  234. choose to simply ignore keypresses, or deal with them as appropriate.
  235. Control characters are not a part of this protocol, as handshaking is
  236. not relevant with proper host construction, and the COMMAND-X keypress
  237. is withheld for remote use to exit the graphics mode.                                                            
  238.